home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 132 < prev    next >
Text File  |  1996-08-06  |  2KB  |  50 lines

  1. Path: fsgm01.fnal.gov!not-for-mail
  2. From: b91926@fsgm01.fnal.gov (David Sachs)
  3. Newsgroups: comp.std.c
  4. Subject: Re: ... char * * promotion to char const * const * ...
  5. Date: 17 Jan 1996 16:45:23 -0600
  6. Organization: FERMILAB, Batavia, IL
  7. Message-ID: <4dju63$9mq@fsgm01.fnal.gov>
  8. References: <4dgj8q$qin@unix.sri.com> <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de> <DLBzGB.J60@polo.demon.co.uk>
  9. Reply-To: sachs@fnal.fnal.gov
  10. NNTP-Posting-Host: fsgm01.fnal.gov
  11. X-Newsreader: NN version 6.5.0 #4 (NOV)
  12.  
  13. john@polo.demon.co.uk (John Winters) writes:
  14.  
  15. >In article <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de>,
  16. >James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> wrote:
  17. >[snip]
  18. >>
  19. >>Originally, the C standard was going to allow this; in fact, it was
  20. >>going to allow all casts which added const anywhere in the type.  Then
  21. >>someone pointed out that the conversion 'char ** -> char *const *' was
  22. >>unsafe.  As a result, the wording was changed to only allow adding the
  23. >>const at the top level.
  24.  
  25. >Interesting.  Could you enlighten us (well, me anyway) as to *why* it
  26. >is unsafe.  I don't find it immediately obvious.
  27.  
  28. Actually 'char ** -> char *const *' is a safe conversion. The related
  29. UNSAFE conversion is 'char ** -> const char **'. This is unsafe
  30. because you could use this conversion to change a constant char.
  31.  
  32. e.g.
  33.  
  34. const char a = 'a';
  35. char b;
  36. char *bb = b;
  37. char **bbb = bb;
  38. const char** ccc;
  39. /* The following statement is an illegal cnversion */
  40. ccc = bbb;
  41. /* Assume the preceding conversion were legal - we could now do */
  42. *ccc = &a;
  43. /* bb now points to a */
  44. *bb = 'b';
  45. /* We have just changed the constant character variable a */
  46. -- 
  47. ** The Klingons' favorite food was named by the first earthling to see it **
  48. David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
  49. Voice: 1 708 840 3942      Deparment Fax: 1 708 840 3785
  50.